package com.example.pucha_xian;

import android.app.Activity;
import android.app.Application;
import android.content.Context;

import com.blankj.utilcode.util.Utils;

import org.litepal.LitePal;

import java.util.LinkedList;
import java.util.List;


public class DemoApplication extends Application {
    public static Context context;
    private List<Activity> activityList = new LinkedList<Activity>();
    private static DemoApplication instance;
    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        LitePal.initialize(context);
      /*  在使用SDK各组件之前初始化context信息，传入ApplicationContext
        SDKInitializer.initialize(this);*/
        Utils.init(this);
    }

    public static Context getContext(){
        return context;
    }

    //单例模式中获取唯一的MyApplication实例
    public static DemoApplication getInstance() {
        if(null == instance) {
            instance = new DemoApplication();
        }
        return instance;
    }

    //添加Activity到容器中
    public void addActivity(Activity activity)  {
        activityList.add(activity);
    }

    //遍历所有Activity并finish
    public void exit() {
        for(Activity activity:activityList) {
            activity.finish();
        }
        activityList.clear();
    }
}
